package com.shiguiwu.springboot3.starter.config;

import com.shiguiwu.springboot3.starter.property.MyProperties;
import com.shiguiwu.springboot3.starter.service.MyService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 自动配置
 * @author: stone
 * @date: Created by 2023/7/8 23:10
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springboot3.starter.config
 */
@EnableConfigurationProperties(MyProperties.class)
@Configuration
@ConditionalOnWebApplication
public class MyAutoConfigure {

    @Bean
    @ConditionalOnProperty(prefix = "my", name = "enabled", matchIfMissing = true)
    public MyService myService(MyProperties myProperties) {
        return new MyService(myProperties);
    }

}
